package com.example.cunion.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.cunion.entity.ActClass;
import com.example.cunion.entity.User;
import com.example.cunion.exception.CunionException;
import com.example.cunion.mapper.ActClassMapper;
import com.example.cunion.service.ActClassService;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
@Configuration
public class ActClassServiceImpl implements ActClassService {

    @Resource
    private ActClassMapper actClassMapper;

   @Override
    public ArrayList searchAllActClass(String position) {
        //根据位置查找所有的活动类
        ArrayList<HashMap> list = actClassMapper.searchAllActClass(position);
        return list;
    }

    @Override
    public Integer addActClass(ActClass actClass) {
        int insert = actClassMapper.insert(actClass);
        if (insert != 1){
            throw new CunionException("添加失败");
        }
        return insert;
    }

    @Override
    public Integer deletedActClass(String actClassId) {
        int result = actClassMapper.deleteById(actClassId);
        if (result != 1){
            throw new CunionException("删除失败！");
        }
        return result;
    }

    @Override
    public Integer updateActClass(ActClass actClass) {
        int result = actClassMapper.updateById(actClass);
        if (result != 1){
            throw new CunionException("修改失败");
        }
        return result;
    }

    @Override
    public List<ActClass> searchActClass(Integer start, Integer length) {
        Page<ActClass> page = new Page<>(start, length);
        QueryWrapper<ActClass> userQueryWrapper = new QueryWrapper<>();
        Page<ActClass> selectPage = actClassMapper.selectPage(page, userQueryWrapper);
        List<ActClass> list = selectPage.getRecords();
        return list;
    }
}
